{
 "metadata": {
  "name": "",
  "signature": "sha256:cb93d043019583326c0d63bbbdc20c5e315beec9df3c4f2372243ab77d035675"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Getting Twitter data using the API\n",
      "import twitter"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "IMPORTANT: BEFORE THIS GOES LIVE, SET THE FOLLOWING KEYS AND SECRETS TO \"INSERT KEY HERE\""
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "consumer_key = \"52Nu7ubm2szT1JyJEOB7V2lGM\"\n",
      "consumer_secret = \"mqA94defqjioyWeMxdJsSduthxdMMGd2vfOUKvOFpm0n7JTqfY\"\n",
      "access_token = \"16065520-USf3DBbQAh6ZA8CnSAi6NAUlkorXdppRXpC4cQCKk\"\n",
      "access_token_secret = \"DowMQeXqh5ZsGvZGrmUmkI0iCmI34ShFzKF3iOdiilpX5\"\n",
      "authorization = twitter.OAuth(access_token, access_token_secret, consumer_key, consumer_secret)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 18
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import os\n",
      "output_filename = os.path.join(os.path.expanduser(\"~\"), \"Data\", \"twitter\", \"python_tweets.json\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import json"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "t = twitter.Twitter(auth=authorization)\n",
      "\n",
      "with open(output_filename, 'a') as output_file:\n",
      "    search_results = t.search.tweets(q=\"python\", count=100)['statuses']\n",
      "    for tweet in search_results:\n",
      "        if 'text' in tweet:\n",
      "            print(tweet['user']['screen_name'])\n",
      "            print(tweet['text'])\n",
      "            print()\n",
      "            output_file.write(json.dumps(tweet))\n",
      "            output_file.write(\"\\n\\n\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "momomi_752\n",
        "RT @seira_923: [Python] Help with a tricky loop issue, how do you use continue to  http://t.co/H54k0nWDiN http://t.co/FydAl78nvH\n",
        "\n",
        "ikuho_379\n",
        "RT @otoka_380: Python/Flask app using apache/fastcgi producing 500 Error http://t.co/sn4d0S5aHD\n",
        "\n",
        "benignowl\n",
        "?? \uc774\uac74 visual studio \uc5d0\ub7ec\uc778\uac00 python \ucef4\ud30c\uc77c\ub7ec\ub85c \ub3cc\ub9ac\uba74 \uc5d0\ub7ec \uc548\ub098\uace0 \uc798 \ub3cc\uc544\uac00\ub294\ub370 vs \ub514\ubc84\uac70\ub85c \ub3cc\ub9ac\uba74 \uc5d0\ub7ec\ub97c \ubc49\uc5b4\ub0b4\ub294\uad70\n",
        "\n",
        "GsonMathias\n",
        "F\u00f6rsta klassens \"tomte\" #moron http://t.co/yMt1PZU1Cp\n",
        "\n",
        "brewokr\n",
        "Python #private #class variables that aren't class variables: When trying to access\u2026 http://t.co/4yIhHsIizx\n",
        "\n",
        "mima_tea\n",
        "\u201cPython\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30c4\u30fc\u30c8\u30c3\u30d7\u300cPylearn2\u300d\u300cCaffe\u300d\u3068\u306f\uff5ePyData Tokyo Meetup #1\u30a4\u30d9\u30f3\u30c8\u30ec\u30dd\u30fc\u30c8 \uff081/3\uff09\uff1aCodeZine\u201d http://t.co/M5qsyZZTnD\n",
        "\n",
        "elena_casanovas\n",
        "Four Beautiful Python, R, MATLAB, and Mathematica plots with LaTeX http://t.co/8krYerBJfB via @rbloggers\n",
        "\n",
        "io_python\n",
        "@0243Kyon http://t.co/mSyeNVcahe\n",
        "\n",
        "0243Kyon\n",
        "@io_python \u3046\u308f\u3041...\n",
        "\n",
        "BlueWaterMarket\n",
        "#Freelancer Python Restless Example by homejinni http://t.co/QRDLJxlsIM #computer via @BlueWaterMarket\n",
        "\n",
        "BlueWaterMarket\n",
        "#Freelancer Python Crawler/Indexer/Spider/Bot by meetire http://t.co/CbzQTdVXdi #computer via @BlueWaterMarket\n",
        "\n",
        "io_python\n",
        "@0243Kyon \u6ce3\u3051\u3088(\u30b2\u30b9\u9854)\n",
        "\n",
        "CashBoards\n",
        "#Freelancer #seo Python Restless Example by homejinni http://t.co/RmZQVvMlz2 @CashBoards\n",
        "\n",
        "CashBoards\n",
        "#Freelancer #seo Python Crawler/Indexer/Spider/Bot by meetire http://t.co/GWf3vHkZ30 @CashBoards\n",
        "\n",
        "pypi_updates\n",
        "SchemePy 1.1.01: R5RS scheme interpreter, supporting hygenic macros and full call/cc http://t.co/cN4bfcStmm\n",
        "\n",
        "yaakov_h\n",
        "RT @shiftkey: current status: installing the other version of python\n",
        "\n",
        "yaakov_h\n",
        "RT @shiftkey: current status: installing python\n",
        "\n",
        "artwisanggeni\n",
        "#python floraconcierge-client 0.6.7: FloraExpress API python client library. http://t.co/0TfRRqsOR8 http://t.co/Ew6FJoY9Hx\n",
        "\n",
        "artwisanggeni\n",
        "#python printNest21 1.4.0: A simple printer of nested lists http://t.co/1OPTOogruI\n",
        "\n",
        "artwisanggeni\n",
        "#python pyupp 0.1: Read and write unity player preferences data. http://t.co/SF7gUilR8x\n",
        "\n",
        "artwisanggeni\n",
        "#python musa 3.3.13: Module for music tagging and library management http://t.co/Wg2qcbMeCS\n",
        "\n",
        "Music_Reddit\n",
        "Lady - Python [Hiphop?] https://t.co/nekBNpmHvL\n",
        "\n",
        "Python_Bob123\n",
        "https://t.co/WKdTIueR9S\n",
        "\n",
        "distantcam\n",
        "RT @shiftkey: current status: installing the other version of python\n",
        "\n",
        "distantcam\n",
        "RT @shiftkey: current status: installing python\n",
        "\n",
        "kfujii\n",
        "\u201chttp://t.co/oAqSNLIRXP\uff1a Python\u8a00\u8a9e\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30a4\u30f3\u30c8\u30ed\u30c0\u30af\u30b7\u30e7\u30f3: \u4e16\u754c\u6a19\u6e96MIT\u6559\u79d1\u66f8: \u4e45\u4fdd \u5e79\u96c4, John V. Guttag, \u9ebb\u751f \u654f\u6b63, \u6728\u6751 \u6cf0\u7d00, \u5c0f\u6797 \u548c\u535a, \u95a2\u53e3 \u826f\u884c\u2026\u201d http://t.co/qAmAQ0skir\n",
        "\n",
        "projectsuperior\n",
        "Top hourly 'python' htags [bm500.., #python, #cgyvsvan, #rdsch, #3dmu] 377 tweets http://t.co/l5IY5gFCyK http://t.co/CEOidrDhmv\n",
        "\n",
        "yutuki_355\n",
        "RT @yuhiro_274: Linking python as backed when using Django + Bower + Grunt http://t.co/MDMfhkRyKS\n",
        "\n",
        "1LuxuryLifeMag\n",
        "@Michael_Louis_ Python Accessories\n",
        "\n",
        "Available Now At -\u2026 http://t.co/tvgQugZZT5\n",
        "\n",
        "tgmp10\n",
        "Black Hat Python: Python Programming for Hackers and Pentesters http://t.co/qBknn5EDOX 3325 http://t.co/JpLvvwjPOz\n",
        "\n",
        "No_not_that_one\n",
        "RT @SamuelHLowe: - Excuse me, do you have snake belts?\n",
        "- Not sure, but I can check in the back.\n",
        "- Please do, my python's pants keep falling\u2026\n",
        "\n",
        "if1live\n",
        "perl oneliner, python oneliner \ub4f1\ub4f1\uc758 \uc5b8\uc5b4\ubcc4 oneliner\uc911\uc5d0\uc11c \uac00\uc7a5 \ubcc0\ud0dc\ub294 lisp \uacc4\uc5f4 \uc544\ub2d0\uae4c?\n",
        "\n",
        ".....)))))))))))\n",
        "\n",
        "pypi_updates\n",
        "floraconcierge-client 0.6.7: FloraExpress API python client library. http://t.co/dXyHxnjqcK http://t.co/wo4TTGYIHx\n",
        "\n",
        "irigo56\n",
        "RT @ElBaulDeKubrick: Still Flying, un tributo a los Monty Python http://t.co/PYb9h5Gssk \u00bfAlguien los ha olvidado? http://t.co/TooNHtSiMm\n",
        "\n",
        "R_Programming\n",
        "Four Beautiful Python, R, MATLAB, and Mathematica plots with LaTeX http://t.co/Dgpmvoocdn #rstats\n",
        "\n",
        "ydfished\n",
        "@Bergg69 @Canada yep. Like Monty Python 'Dennis Moore' sketch. Rob the poor to give to the rich.\n",
        "\n",
        "sawa_453\n",
        "RT @urara_645: Keep This Python Cheat Sheet on Hand When Learning to Code http://t.co/R72YIj24j4 http://t.co/FtEYHLwj6H\n",
        "\n",
        "mirage_1205\n",
        "RT @mura_cin: Python\u3067\u5909\u6570\u540d\u3092\u3064\u3051\u308b\u3068\u304d\u306b\u306f\u4e88\u7d04\u8a9e\u3060\u3051\u3067\u306a\u304f\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u3068\u306e\u885d\u7a81\u3082\u6c17\u3092\u4ed8\u3051\u307e\u3057\u3087\u3046 on @Qiita http://t.co/1n5c7ut7Dl\n",
        "\n",
        "rinna_815\n",
        "RT @seira_923: [Python] Is this if-statement correct (conceptually)? http://t.co/dYy9pXaSkj http://t.co/p42JgUVIEV\n",
        "\n",
        "yuko_267\n",
        "Is there any reason I should witch to python 3 http://t.co/t17y7JI92b http://t.co/A0oxjbpOn2\n",
        "\n",
        "pypi_updates\n",
        "printNest21 1.4.0: A simple printer of nested lists http://t.co/h5iLQ3zTil\n",
        "\n",
        "yakmoose\n",
        "@shiftkey a python install for you! And a python install for you. Everyone gets a python install!\n",
        "\n",
        "sashiya_107\n",
        "RT @seino_988: Making GIFs from Video Files with Python http://t.co/xOelfi2SKU\n",
        "\n",
        "MAMI_nagisa_\n",
        "@python_octopus \u304a\u75b2\u308c\u3055\u307e\u3067\u3057\u305f\uff01\u3053\u308c\u3067\u5fc3\u7f6e\u304d\u306a\u304f\u3067\u3059\u304b\u2026\uff1f\n",
        "\n",
        "sinatrasapporo\n",
        "RT @kuroneko1988: \u3054\u3081\u3093\u306a\u3055\u3044\uff0e\u3054\u3081\u3093\u306a\u3055\u3044\uff0e\u3084\u3063\u3064\u3051\u3067\u3059/Sinatra\u98a8\u30de\u30a4\u30af\u30ed\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u59cb\u3081\u308bPython http://t.co/0rCghxCNGh @SlideShare\u3055\u3093\u304b\u3089\n",
        "\n",
        "Python_Bob123\n",
        "https://t.co/basmBzXZNb\n",
        "\n",
        "yuno_730\n",
        "RT @seira_923: Python: Is it a good starting point? http://t.co/mvnIxwRn8V http://t.co/vTVQPN16XF\n",
        "\n",
        "python_octopus\n",
        "@halulan \u87fb\u3067\u3059\uff01\uff01\n",
        "\n",
        "Python_Bob123\n",
        "Fuck work.\n",
        "\n",
        "halulan\n",
        "@python_octopus \n",
        "\u4e59\u3067\u3059\uff01\uff01\n",
        "\n",
        "WomansIndex\n",
        "Vince Camuto Women's VC/5022RGBN Leather Rosegold-Tone Date Function Brown Python Strap Watch   http://t.co/imePT9i3gx\n",
        "\n",
        "ArchUpdates\n",
        "python-rpy2 2.5.4-1 x86_64 http://t.co/oawb8APara #Archlinux\n",
        "\n",
        "ArchUpdates\n",
        "python-rpy2 2.5.4-1 i686 http://t.co/TnMRb22DI2 #Archlinux\n",
        "\n",
        "shiftkey\n",
        "current status: installing the other version of python\n",
        "\n",
        "shiftkey\n",
        "current status: installing python\n",
        "\n",
        "miyoshi_107\n",
        "Using BOTH error bars and upper/lower limits in python http://t.co/X5FyAWHikJ\n",
        "\n",
        "DoubleDownDuck\n",
        "RT @NYDailyNews: A 15-foot Burmese python was found at a Florida real estate office. http://t.co/ry0yXBZ6Ek http://t.co/1CQVQuZVjj\n",
        "\n",
        "python_octopus\n",
        "@kazunaduck \u304a\u3064\u3042\u308a\u3067\u3059\u3046\u3047\u3072\u3072\u3072\u3072\uff01\uff01\n",
        "\n",
        "naoka_870\n",
        "Woman Finds Python In Secondhand S-s-s-s-sofa http://t.co/hvWepmNbD6 http://t.co/r2g2xHF0kE\n",
        "\n",
        "kazunaduck\n",
        "@python_octopus \u304a\u75b2\u308c\u3055\u307e\u3067\u3059\u3046\u3047\u3078\u3078\u3078\u3078\uff01\uff01\n",
        "\n",
        "python_octopus\n",
        "@Escalator_Rider \u300e\u304a\u3064\u3042\u308a\u3055\u307e\u3063\u3059\u300f\n",
        "\n",
        "python_octopus\n",
        "@kobudashiOdashi \u3042\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\n",
        "\n",
        "Data88Geek\n",
        "RT @Python_Quest: How to add assumptions in limit in Sympy? http://t.co/um3d45PzDu http://t.co/t3TXOZrjLV #Python via @dv_geek\n",
        "\n",
        "Data88Geek\n",
        "RT @Python_Quest: Dealing with list.index(x) error in Python 3 http://t.co/0jp5moJqwh http://t.co/Ntbf0XWdt2 #Python via @dv_geek\n",
        "\n",
        "Escalator_Rider\n",
        "@python_octopus \u300e\u304a\u3064\u304b\u308c\u3055\u307e\u3063\u3059\u300f\n",
        "\n",
        "python_octopus\n",
        "@mechashiorina \u304a\u3064\u3042\u308a\u3067\u3054\u3056\u3044\u307e\u3059\uff01\uff01\n",
        "\n",
        "Wiajbo__Vuuzqa\n",
        "Michael Kors Hamilton Python Embossed Leather Large Brown Mocha Tote Purse Bag - Full read by eBay: Price 339.0 USD\u2026 http://t.co/IkkhhgJrrn\n",
        "\n",
        "JimmyMcH\n",
        "Monty Python - Always Look on the Bright Side of \u2026: http://t.co/xYHUiKxp4K\n",
        "\n",
        "kobudashiOdashi\n",
        "@python_octopus \u304a\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\u3063\uff54\n",
        "\n",
        "mechashiorina\n",
        "@python_octopus \u304a\u3064\u304b\u308c\u3055\u307e\u3067\u3059\uff01\uff01\n",
        "\n",
        "regis_alenda\n",
        "RT @GodDonut: Python *finira* par \u00eatre un langage typ\u00e9 https://t.co/USii3gwnWa . Mais forc\u00e9ment, comme pour tout le reste, \u00e7a sera mal fait.\n",
        "\n",
        "python_octopus\n",
        "@mkmnsh_ \u304a\u3064\u3042\u308a\u3067\u3054\u3056\u3044\u307e\u3059\uff01\uff01\n",
        "\n",
        "shkoga\n",
        "C++ \u3067\u66f8\u304b\u308c\u305f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u3001C# \u3068\u3001\u305d\u308c\u304b\u3089 F# \u3068 Python (IronPython) \u3067\u66f8\u304d\u76f4\u3057\u3066\u307f\u307e\u3059\u304b\u306a\u3002\n",
        "\n",
        "mkmnsh_\n",
        "@python_octopus \u304a\u3064\u304b\u308c\u3055\u307e\u3067\u3059\uff01\n",
        "\n",
        "brewokr\n",
        "How to protect python class variables from an evil programmer?: How can I protect my\u2026 http://t.co/n0AzC6hWWw\n",
        "\n",
        "python_jobs\n",
        "Object Initialization -- Patterns And Antipatterns - http://t.co/Pi5xu4NMkR\n",
        "\n",
        "python_octopus\n",
        "\u7de0\u5207\u307e\u30675\u6642\u9593\u534a\u3002\u3044\u3064\u3082\u304e\u308a\u304e\u308a\u3067\u3059\u306a\u3041\u3002\n",
        "\n",
        "mrsergani\n",
        "Python! http://t.co/JjdDGlGba1\n",
        "\n",
        "abadahenno\n",
        "How do I convert this piece of code written in Python 3.4 into Python 2.7 (gives error with end)? http://t.co/Yn5WvjVHZD #Question\n",
        "\n",
        "Python_Quest\n",
        "Dealing with list.index(x) error in Python 3 http://t.co/0jp5moJqwh http://t.co/Ntbf0XWdt2 #Python via @dv_geek\n",
        "\n",
        "marie_cali\n",
        "Create a Freelancer/Elance type site by seekdesign http://t.co/1haUCxuI2g\n",
        "\n",
        "Python_Quest\n",
        "How to add assumptions in limit in Sympy? http://t.co/um3d45PzDu http://t.co/t3TXOZrjLV #Python via @dv_geek\n",
        "\n",
        "python_octopus\n",
        "\u3048\u3078\u3078 \u5408\u540c\u8a8c\u539f\u7a3f\u7d42\u308f\u3063\u305f\n",
        "\n",
        "sebalinux\n",
        "I really want to thank @drchuck and @coursera for the great #python course #PR4E. A good starting point, now looking forward to learn more\n",
        "\n",
        "jvw1954\n",
        "RT @pythontrending: Bedfellows - Command-line tool for exploring the PAC donor-recipient relationship http://t.co/gZ5gFWEVTb #python\n",
        "\n",
        "natuha_306\n",
        "RT @yuhiro_274: Django, Python, and Class Variables http://t.co/LnHRC1rQQp\n",
        "\n",
        "MyNextWifey\n",
        "\"Doctor, I keep thinking I'm a python. Oh you can't get round me like that, you know.\"\n",
        "\n",
        "jvw1954\n",
        "RT @pythontrending: eatiht - A tool for extracting article text in html documents. http://t.co/Wu2jxwHpWE #python\n",
        "\n",
        "rssnest\n",
        "24.6 10.2 http://t.co/hYAym4DQUR pyupp added to PyPI\n",
        "\n",
        "IJInformatico\n",
        "#empleo #IT A/P   PYTHON   PHP  Y   JAVA - Madrid http://t.co/2HPny4tseI\n",
        "\n",
        "LearnEnglPhuket\n",
        "rt Monty Python's Silly Walk to PHUKET LEARN GOOD ENGLISH -  http://t.co/GiZnKicQMf\n",
        "\n",
        "NuphaUtsen\n",
        "rt Monty Python's Silly Walk to PHUKET LEARN GOOD ENGLISH -  http://t.co/xH9w7LcUW9\n",
        "\n",
        "IrishCause\n",
        "rt Monty Python's Silly Walk to PHUKET LEARN GOOD ENGLISH -  http://t.co/5jDQynuWnl\n",
        "\n",
        "thedamnwells\n",
        "Let us always carry with us into each generation the legacy of Monty Python.\n",
        "\n",
        "satoe_445\n",
        "RT @kinori51: Can't input (\u010d \u0107 \u0161 \u017e \u0111 ) in python 2.7.x console [duplicate] http://t.co/WCev9si6nK\n",
        "\n",
        "python_octopus\n",
        "\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\n",
        "\n",
        "pgdkg\n",
        "Python Data Visualization Cookbook http://t.co/W18vDQBzgE 1728 http://t.co/FeGqj442Gy\n",
        "\n",
        "patatostew\n",
        "monty python http://t.co/t6g9nDIlJL\n",
        "\n",
        "aussiecoley\n",
        "RT @NYDailyNews: A 15-foot Burmese python was found at a Florida real estate office. http://t.co/ry0yXBZ6Ek http://t.co/1CQVQuZVjj\n",
        "\n",
        "python_octopus\n",
        "\u308a\u3063\u8336\u5e97\u306f\u4f55\u6642\u307e\u3067\u3067\u3059\u304b\uff1f\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 21
    }
   ],
   "metadata": {}
  }
 ]
}